package com.cy.stone.system.domain.clientobject.role;

import com.cy.stone.common.base.AddGroup;
import com.cy.stone.common.base.EditGroup;
import com.cy.stone.system.infrastructure.database.entity.RoleEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;

/**
 * 角色入参
 * @author Wings
 * @since 2023-12-10
 */
@Data
@Schema(name = "角色入参")
public class RoleCO {

    @Schema(description = "ID",  requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotEmpty(message = "ID不能为空", groups = EditGroup.class)
    private String id;

    @Schema(description = "角色码", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "角色码不能为空", groups = { AddGroup.class, EditGroup.class })
    private String roleCode;

    @Schema(description = "角色名", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "角色名不能为空", groups = { AddGroup.class, EditGroup.class })
    private String roleName;

    public static RoleEntity toAddEntity(RoleCO roleCO) {
        RoleEntity role = new RoleEntity();
        role.setRoleCode(roleCO.getRoleCode());
        role.setRoleName(roleCO.getRoleName());
        return role;
    }

    public static void updateEntity(RoleCO roleCO, RoleEntity roleEntity) {
        roleEntity.setRoleCode(roleCO.getRoleCode());
        roleEntity.setRoleName(roleCO.getRoleName());
    }
}
